package lagou.demo;

import com.alibaba.druid.util.JdbcUtils;

import java.sql.*;
import java.util.Date;
import java.util.Scanner;

public class JABC01 {
    public static void main(String[] args) throws Exception {
//1.注册驱动
// forName 方法执行将类进行初始化
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接 url,用户名, 密码
        String url = "jdbc:mysql://localhost:3306/db?characterEncoding=UTF-8";
        Connection con = DriverManager.getConnection(url, "root", "123456");
//com.mysql.jdbc.JDBC4Connection@2e3fc542

        Statement statement = con.createStatement();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入查找用户名: ");
        String name = sc.nextLine();
        System.out.println("请输入性别: ");
        String gender = sc.nextLine();

        String sql="Select * from db.employee where name = ? and gender = ?";
        PreparedStatement ps= con.prepareStatement(sql);
        ps.setString(1,name);
        ps.setString(2,gender);
        ResultSet resultSet = ps.executeQuery();
        while(resultSet.next()){
            // 通过列名的方式获取
            int id = resultSet.getInt("id");
            String NAME = resultSet.getString("NAME");
            String sex = resultSet.getString("gender");
            double salary = resultSet.getDouble("salary");
            double bonus = resultSet.getDouble("bonus");
            Date join_date = resultSet.getDate("join_date");

            System.out.println(id + " : " + NAME + " : " + sex + " : "  + salary + " : "+ bonus + " : " + join_date  );
        }
//6.释放资源
 resultSet.close();
        ps.close();
        con.close();

    }
}
